package com.onlineclass.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.demo.util.JDBCUtils;
import com.onlineclass.bean.Tag;

/**
 * 标签DAO
 * @author david
 *
 */
public class TagDAO {
	static QueryRunner qr = new QueryRunner();

	
	/**
	 * 根据topId查询指定级别的分类
	 * @param topId
	 * @return
	 */
	public List<Tag> list(Integer topId) {
		try {
			List<Tag> list = qr.query(
					JDBCUtils.getConnection(), 
					"select * from t_tag where topId=?",
					new BeanListHandler<Tag>(Tag.class),
					topId);
			return list;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	// 根据传入的一级分类，返回所有二级分类ID    100,101,102
	public List<Integer> listTags(Integer tag){
		List<Integer> ids = new ArrayList<Integer>();
		List<Tag> list = list(tag);
		for (Tag t : list) {
			ids.add(t.getId());
		}
		return ids;
	}
	
	public static void main(String[] args) {
		
	}
}
